<template>
  <div style="cursor: pointer">
    <el-tag :type="type" @click="handleClick">{{ text }}</el-tag>
  </div>
</template>

<script>
export default {
  props: {
    value: {
      type: String
    },
    // 本行的所有数据，此字段不需要额外配置
    scope: {
      default: null
    },
    // 通过 component 中 props 字段传过来的数据，此字段需要先在 component 中配置
    myProps: {
      default: null
    }
  },
  computed: {
    type () {
      return this.value ? 'success' : 'danger'
    },
    text () {
      return this.value ? '查看详情' : '生成失败'
    }
  },
  mounted () {
    console.log(this.scope)
    // console.log(this.myProps)
  },
  methods: {
    handleClick () {
      var host = 'https://git.zz.com/'
      var project = this.scope.row.project
      var server = ['iris', 'venus', 'saturn', 'mimas', 'ceres', 'deimos', 'jupiter', 'mars', 'spider', 'pine', 'phobos', 'uranus', 'forest', 'glacier', 'hail', 'lake', 'mountain', 'rainbow', 'yellowbee']
      var h5 = ['tomatovine', 'tomato', 'melon', 'coconut', 'jackfruit', 'Raisins', 'peach', 'pear', 'lemon', 'cherry', 'mango', 'durian', 'orange']
      var domain = null
      if (server.indexOf(project) > -1) {
        domain = 'server'
      } else if (h5.indexOf(project) > -1) {
        domain = 'h5'
      }
      if (!domain) {
        alert('项目不在域！')
        return
      }
      var url = host + domain + '/' + this.scope.row.project + '/-/commit/' + this.value

      if (this.value) {
        window.open(url, '_blank')
      }
    }
  }
}
</script>
